/**
 * 
 */
package inet.app.model.util;

import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;

/**
 * @author blue dragon
 *
 */
public class TimeConsumingTaskRunnable implements Runnable{
	boolean isRunning = false;
	private ProgressDialog pDialog;
	private TimeConsummingTaskInterface tcTask;
	
	public TimeConsumingTaskRunnable(TimeConsummingTaskInterface tcTask){
		this.tcTask = tcTask;		
	}
	
	@Override
	public void run() {
		isRunning = true;
		tcTask.runTask();
		if(isRunning)
			updateUIHandler.sendEmptyMessage(0);
		isRunning = false;
	}
	
	public void stop(){		
		isRunning = false;
	}
	
	public boolean isRunning() {
		return isRunning;
	}
	public void setRunning(boolean isRunning) {
		this.isRunning = isRunning;
	}
	
	public Handler updateUIHandler = new Handler(){
		@Override
		public void handleMessage(Message msg) {	
			pDialog.dismiss();
			tcTask.updateGUI();
		}
	};

	public ProgressDialog getProcessDialog() {
		return pDialog;
	}

	public void setProcessDialog(ProgressDialog pDialog) {
		this.pDialog = pDialog;
	}
	

}
